﻿using ShoppingCar.shopping;
using ShoppingCar.ShoppingCars;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace ShoppingCar
{
    public class CarAppService : ApplicationService, ICarService
    {
        private readonly IRepository<Car, int> _car;

        public CarAppService(IRepository<Car, int> car)
        {
            _car = car;
        }
        public int CreateCar(CreateUpdateCarDto dto)
        {
            var add = new Car()
            {
            ShoppingCartId=dto.ShoppingCartId,
            CommodityId =dto.CommodityId,
            ShoppingCartNum =dto.ShoppingCartNum,
            MemberId =dto.MemberId,
            EvaluaTime =dto.EvaluaTime,
            ShoppingCartPrice =dto.ShoppingCartPrice,
            Shoppingheadline =dto.Shoppingheadline,
            Shoppingintroduce =dto.Shoppingintroduce
            };
            _car.InsertAsync(add);
            return 10;
        }

        public List<CarListDto> GetCarLists()
        {
            var get = from a in _car
                      select new CarListDto
                      {
                          Id=a.Id,
                          ShoppingCartId=a.ShoppingCartId,
                          CommodityId=a.CommodityId,
                          ShoppingCartNum=a.ShoppingCartNum,
                          MemberId=a.MemberId,
                          EvaluaTime=a.EvaluaTime,
                          ShoppingCartPrice=a.ShoppingCartPrice,
                          Shoppingheadline=a.Shoppingheadline,
                          Shoppingintroduce=a.Shoppingintroduce
                      };
            var list = get.ToList();
            return list;
        }
    }
}
